package boot.config;

import boot.utils.StringToPet;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Author: fengshun
 * @Date:2024/8/16 15:30
 * @DESC:
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Resource
    private StringToPet stringToPet;
    @Resource
    private MyInterceptor myInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        System.out.println("myInterceptor = " + myInterceptor);
        registry.addInterceptor(myInterceptor).addPathPatterns("/**").excludePathPatterns("/login.html","/login");
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**").addResourceLocations("file:/D:\\workspace\\idea\\JKY\\testSpringBoot\\boot3_web_thymeleaf\\src\\main\\resources\\static\\pic\\");
    }
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(stringToPet);
    }

}
